Skip to content

Conversation

@matthewdavi
Copy link

Based on a Discord discussion with @KyleAMathews, this PR attempts to implement a union operator to join multiple live query collections in a single useLiveQuery call, which is needed for a number of things, among them, working around react hooks not being callable inside a loop.

🎯 Changes

This adds union and unionFromLiveQuery utilities for combining collections, with fail-fast key conflict detection and ref-counted dynamic unions driven by live query results. It also adds tests for union behavior, conflicts, and ref-counted removal.

Issue: #58

Usage:

import { union, unionFromLiveQuery } from '@tanstack/db'

const unified = union(collectionA, collectionB)

const dynamicUnified = unionFromLiveQuery(
  (q) => q.from({ feed: feedsCollection }),
  ({ feed }) =>
    createCollection(
      rssFeedsCollectionOptions({
        url: feed.url,
      }),
    ),
)

Local checks:

  • pnpm tsc -p packages/db/tsconfig.json --noEmit
  • pnpm --filter "./packages/**" lint (warnings pre-existing in repo)
  • pnpm --filter @tanstack/db-ivm build
  • pnpm --filter @tanstack/db build
  • pnpm --filter @tanstack/electric-db-collection build
  • pnpm --filter "./packages/**" test

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

@changeset-bot
Copy link

changeset-bot bot commented Jan 17, 2026

⚠️ No Changeset found

Latest commit: 06a09ef

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant